package com.csun.cmny.provider.controller.admin;

import com.csun.cmny.base.dto.LoginAuthDto;
import com.csun.cmny.core.annotation.ValidateAnnotation;
import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.DmcWatchConf;
import com.csun.cmny.provider.model.dto.watch.*;
import com.csun.cmny.provider.model.enums.watch.WatchTimeZoneEnum;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.DmcWatchConfigService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-01-17 16:11
 * @Description: the class dmc watch config controller
 */
@RestController
@RequestMapping(value = "/watch", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DmcWatchConfigController extends BaseController {

    @Resource
    private DmcWatchConfigService watchConfigService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    /**
     * 查询手环配置
     */
    @ValidateAnnotation
    //@LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/queryDmcWatchConfigByDeviceId/{deviceId}", method = RequestMethod.POST)
    public Wrapper queryDmcWatchConfigByDeviceId(@PathVariable Long deviceId) {

        DmcWatchConf dmcWatchConf = watchConfigService.queryDmcWatchConfigByDeviceId(deviceId);

       // return WrapMapper.ok(dmcWatchConf);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),dmcWatchConf);
    }

    /**
     * 亲情号码设置
     */
    @ValidateAnnotation
    //@LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchFamilyNumber", method = RequestMethod.POST)
    public Wrapper setWatchFamilyNumber(@Validated @RequestBody WatchFamilyNumberDto watchFamilyNumberDto,
                                        BindingResult br) {

        Integer result = watchConfigService.setWatchFamilyNumber(watchFamilyNumberDto,
                getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 心率上传间隔频率设置
     */
    @ValidateAnnotation
    //@LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchHeartUploadRate", method = RequestMethod.POST)
    public Wrapper setWatchHeartUploadRate(@Validated @RequestBody WatchHeartUploadRateDto watchHeartUploadRateDto,
                                           BindingResult br) {

        Integer result = watchConfigService.setWatchHeartUploadRate(watchHeartUploadRateDto,
                getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * GPS上传间隔设置
     */
    @ValidateAnnotation
    //@LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchGpsUploadRate", method = RequestMethod.POST)
    public Wrapper setWatchGpsUploadRate(@Validated @RequestBody WatchGpsUploadRateDto watchGpsUploadRateDto,
                                         BindingResult br) {

        Integer result = watchConfigService.setWatchGpsUploadRate(watchGpsUploadRateDto,
                getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * GPS静默时间段设置
     */
    @ValidateAnnotation
    //@LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchGpsPeriod", method = RequestMethod.POST)
    public Wrapper setWatchGpsPeriod(@Validated @RequestBody WatchPeriodDto watchPeriodDto,
                                     BindingResult br) {

        Integer result = watchConfigService.setWatchGpsPeriod(watchPeriodDto,
                getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 低电量提醒时间段设置
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchPowerPeriod", method = RequestMethod.POST)
    public Wrapper setWatchPowerPeriod(@Validated @RequestBody WatchPeriodDto watchPeriodDto,
                                       BindingResult br) {

        Integer result = watchConfigService.setWatchPowerPeriod(watchPeriodDto,
                getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 余额不足提醒时间段设置
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchBalancePeriod", method = RequestMethod.POST)
    public Wrapper setWatchBalancePeriod(@Validated @RequestBody WatchPeriodDto watchPeriodDto,
                                         BindingResult br) {

        Integer result = watchConfigService.setWatchBalancePeriod(watchPeriodDto,
                getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/queryWatchTimeZoneList", method = RequestMethod.POST)
    public Wrapper queryWatchTimeZoneList() {

        List<Map<String, String>> timeZoneList = WatchTimeZoneEnum.getMap2List();

      //  return WrapMapper.ok(timeZoneList);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),timeZoneList);
    }

    /**
     * 时区设置
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchTimeZone", method = RequestMethod.POST)
    public Wrapper setWatchTimeZone(@Validated @RequestBody WatchTimeZoneDto watchTimeZoneDto,
                                    BindingResult br) {

        Integer result = watchConfigService.setWatchTimeZone(watchTimeZoneDto,
                getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * GPS开关设置
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchGpsSwitch", method = RequestMethod.POST)
    public Wrapper setWatchGpsSwitch(@Validated @RequestBody WatchSwitchDto watchSwitchDto,
                                     BindingResult br) {

        Integer result = watchConfigService.setWatchGpsSwitch(watchSwitchDto,
                getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 白名单开关设置
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchWhiteListSwitch", method = RequestMethod.POST)
    public Wrapper setWatchWhiteListSwitch(@Validated @RequestBody WatchSwitchDto watchSwitchDto,
                                           BindingResult br) {

        Integer result = watchConfigService.setWatchWhiteListSwitch(watchSwitchDto,
                getLoginAuthDto());

      //  return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 黄键短信开关设置
     */
    @ValidateAnnotation
  //  @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchYellowKeySmsSwitch", method = RequestMethod.POST)
    public Wrapper setWatchYellowKeySmsSwitch(@Validated @RequestBody WatchSwitchDto watchSwitchDto,
                                              BindingResult br) {

        Integer result = watchConfigService.setWatchYellowKeySmsSwitch(watchSwitchDto,
                getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 红键短信开关设置
     */
    @ValidateAnnotation
    //@LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchRedKeySmsSwitch", method = RequestMethod.POST)
    public Wrapper setWatchRedKeySmsSwitch(@Validated @RequestBody WatchSwitchDto watchSwitchDto,
                                           BindingResult br) {

        Integer result = watchConfigService.setWatchRedKeySmsSwitch(watchSwitchDto,
                getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 设置音量等级
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setWatchVolume", method = RequestMethod.POST)
    public Wrapper setWatchVolume(@Validated @RequestBody WatchVolumeDto watchVolumeDto,
                                  BindingResult br) {

        Integer result = watchConfigService.setWatchVolume(watchVolumeDto,
                getLoginAuthDto());

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 查询白名单列表
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/queryWatchWhiteList/{deviceId}", method = RequestMethod.POST)
    public Wrapper queryWatchWhiteListByDeviceId(@PathVariable Long deviceId) {

        List<String> watchWhiteList = watchConfigService.queryWatchWhiteListByDeviceId(deviceId);

       // return WrapMapper.ok(watchWhiteList);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),watchWhiteList);
    }

    /**
     * 添加白名单
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/addWatchWhiteListPhone", method = RequestMethod.POST)
    public Wrapper addWatchWhiteListPhone(@Validated @RequestBody AddWatchWhiteListDto addWatchWhiteListDto,
                                          BindingResult br, LoginAuthDto loginAuthDto) {

        Integer result = watchConfigService.addWatchWhiteListPhone(addWatchWhiteListDto,
                loginAuthDto);

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 修改白名单
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/editWatchWhiteListPhone", method = RequestMethod.POST)
    public Wrapper editWatchWhiteListPhone(@Validated @RequestBody EditWatchWhiteListDto editWatchWhiteListDto,
                                           BindingResult br, LoginAuthDto loginAuthDto) {

        Integer result = watchConfigService.editWatchWhiteListPhone(editWatchWhiteListDto,
                loginAuthDto);

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 删除白名单
     */
    @ValidateAnnotation
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/deleteWatchWhiteListPhone", method = RequestMethod.POST)
    public Wrapper deleteWatchWhiteListPhone(@Validated @RequestBody DeleteWatchWhiteListDto deleteWatchWhiteListDto,
                                             BindingResult br, LoginAuthDto loginAuthDto) {

        Integer result = watchConfigService.deleteWatchWhiteListPhone(deleteWatchWhiteListDto,
                loginAuthDto);

      //  return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }
}
